{extend name="template/base_default"}
{block name="header"}
<link rel="stylesheet" href="__CSS__/common.css">
<link rel="stylesheet" href="__CSS__/checkout/index.css">
{/block}
{block name="body"}
<div class="submit-order">
    <div class="submit-order-img"><img src="__IMG__/shop/submit-order.png"></div>
    <div class="submit-order-address" data-id="{$default_id}">
        <div class="submit-order-address-left">
            <div><span class="submit-order-address-name">{$default_info.contactname}</span><span class="submit-order-address-phone">{$default_info.mobile}</span></div>
            <div class="submit-order-address-detail">{$default_info.province.''.$default_info.city.''.$default_info.area.''.$default_info.detailinfo}</div>
        </div>
        <div class="submit-order-address-right anticon anticon-right"></div>
    </div>
    <div class="submit-order-product" data-id="{$info['id']}">
        <div class="submit-order-product-left">{$info['name']}</div>
        <div class="submit-order-product-right">
            <div class="submit-order-product-money">{$info['price']}积分</div><br/>
        </div>
    </div>

</div>
<div class="submit-order-btn">
    <div class="submit-order-btn-left">总计： <span><span class="total-price">{$info['price']}</span>积分</span></div>
    <button class="submit-order-btn-right">确定</button>
</div>
{/block}
{block name="footer"}
<script type="text/javascript" src="__JS__/public.js"></script>
<script type="text/javascript">
    var pay_order = function(address_id,pid){
        if(address_id==''){
            $.toast('请选择收货地址', "cancel");
            return;
        }

        var form = $('<form></form>');

        var   action =getBaseUrl() + '/weixin/order/product_order';

        form.attr({action:action,method:'post',target:'_self'});
        var address_input = $('<input type="text" name="addressid" />');
        address_input.attr('value',address_id);
        var pid_input = $('<input type="text" name="pid" />');
        pid_input.attr('value',pid);
        form.append(address_input);
        form.append(pid_input);
        $('body').append(form);
        form.submit().remove();
    };
    $('.submit-order-btn-right').click(function(){
        var address_id = $('.submit-order-address').attr('data-id');
        address_id=address_id!=0?address_id:'';
        var pid = $('.submit-order-product').attr('data-id');
        pay_order(address_id,pid);
    });
    //选择地址

    var address = {$address};
    var default_id = {$default_id};
    var ACTIONS = [];
    if(address.length != 0 ){
        ACTIONS = address.map(function(val){
            if(val.id == default_id){
                return(
                    {
                        text: '默认：'+val.contactname+','+val.mobile+','+val.province+val.city+val.area+val.detailinfo,
                        className: "color-primary",
                        onClick: function() {
                            $(".submit-order-address-name").text(val.contactname);
                            $(".submit-order-address-phone").text(val.mobile);
                            $(".submit-order-address-detail").text(val.province+val.city+val.area+val.detailinfo);
                            $('.submit-order-address').attr('data-id',val.id)
                        }
                    }
                )
            }else{
                return(
                    {
                        text: val.contactname+','+val.mobile+','+val.province+val.city+val.area+val.detailinfo,
                        onClick: function() {
                            $(".submit-order-address-name").text(val.contactname);
                            $(".submit-order-address-phone").text(val.mobile);
                            $(".submit-order-address-detail").text(val.province+val.city+val.area+val.detailinfo);
                            $('.submit-order-address').attr('data-id',val.id)
                        }
                    }
                )
            }
        });
    }
    ACTIONS.unshift(
            {
                text: "新增收货地址",
                className: "bg-primary",
                onClick: function() {
                    window.location.href = 'http://mj.8raw.com/minjian/public/weixin.php/weixin/address/address_add.html';
                }
            }
    );
    $(".submit-order-address").click(function() {
        $.actions({
            title: "选择地址",
            onClose: function() {

            },
            actions: ACTIONS
        });
        if(ACTIONS.length>5){
            $('.weui-actionsheet').css('position','relative');
        }
        //更改主题色
        $('.bg-primary').css('background','#f5aa75');
        $('.color-primary').css('color','#f5aa75');
    });

</script>
{/block}